#pragma once
#include "liveMedia/liveMedia.hh"
#include "BasicUsageEnvironment/BasicUsageEnvironment.hh"
#include <iostream>
#include <functional>
#include <string>


typedef std::function<void(SPropRecord*, int, u_int8_t*, unsigned)>  FrameCallBackFunc;

class ourRTSPClient;
class CRtspClient
{
public:
	CRtspClient();
	~CRtspClient();

	//������ͷ
	void Open(UsageEnvironment& env, char const* rtspURL, char const* sUser, char const* sPasswd, FrameCallBackFunc CallBackFunc);

	//�ر�����ͷ
	void Close();

private:
	ourRTSPClient* m_pRtspClient;
};

//ά����״̬��
class StreamClientState {
public:
	StreamClientState();
	virtual ~StreamClientState();

public:
	MediaSubsessionIterator* iter;
	MediaSession* session;
	MediaSubsession* subsession;
	TaskToken streamTimerTask;
	double duration;
};

//��д�ͻ�����
class ourRTSPClient : public RTSPClient {
public:
	static ourRTSPClient* createNew(UsageEnvironment& env, char const* rtspURL,
		int verbosityLevel = 0,
		char const* applicationName = NULL,
		portNumBits tunnelOverHTTPPortNum = 0);

protected:
	ourRTSPClient(UsageEnvironment& env, char const* rtspURL,
		int verbosityLevel, char const* applicationName, portNumBits tunnelOverHTTPPortNum);
	virtual ~ourRTSPClient();

public:
	StreamClientState scs;
	FrameCallBackFunc m_CallBackFunc;
	Authenticator* auth;
};


//�������ݽ�����(����������)
class DummySink : public MediaSink {
public:
	static DummySink* createNew(UsageEnvironment& env,
		MediaSubsession& subsession,
		char const* streamId = NULL);

	FrameCallBackFunc m_CallBackFunc;

private:
	DummySink(UsageEnvironment& env, MediaSubsession& subsession, char const* streamId);
	virtual ~DummySink();

	static void afterGettingFrame(void* clientData, unsigned frameSize,
		unsigned numTruncatedBytes,
	struct timeval presentationTime,
		unsigned durationInMicroseconds);
	void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes,
	struct timeval presentationTime, unsigned durationInMicroseconds);

private:
	virtual Boolean continuePlaying();

private:
	u_int8_t* fReceiveBuffer;
	MediaSubsession& fSubsession;
	char* fStreamId;
};